//************************************************************************
/// <copyrigth>2024-2025 Corporation.All Rights Reserved</copyrigth>
/// <author>tangyingzhong</author>
/// <contact>tangyz114987@outlook.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// Cross-Platform common tool
///</describe>
/// <date>2024/4/14</date>
///***********************************************************************
#ifndef FOUNDATION_H
#define FOUNDATION_H

#include <iostream>
#include <string>
#include <vector>
#include "ModuleLoader/ModuleConfig.h"

namespace SystemTool
{
    class CLASS_ITEM Foundation
    {
    public:
        // Copy stream with block buffer
        static unsigned long long CopyStream(std::istream &is, std::ostream &os, int iBlockSizeForEachCopy = 8192, std::function<void(uint64_t)> fProgressFunc = nullptr);

        // Copy stream to string
        static unsigned long long CopyToString(std::istream &is,std::string& strData, int iBlockSizeForEachCopy = 8192);

        // Copy stream with block buffer
        static unsigned long long CopyStream64(std::istream &is, std::ostream &os, int iBlockSizeForEachCopy = 8192, std::function<void(uint64_t)> fProgressFunc = nullptr);

        // Copy stream to string
        static unsigned long long CopyToString64(std::istream &is,std::string& strData, int iBlockSizeForEachCopy = 8192);

        // Hex to string
        static std::string ToHexString(std::vector<unsigned char>& vByteArr);

        // String to hex
        static bool FromHexString(std::string strHexData, std::vector<unsigned char>& vOutByteArr);

        // Base64 a string
        static std::string ToBase64(std::string &strData);

        // De-base64 the string
        static std::string FromBase64(std::string &strBase64Data);

        // Base64 a file(if bIsKeepNewLineMode=true,every 72 bytes will add \r\n or \n to the end)
        static bool ToBase64(std::ifstream &is, std::ostream &os, bool bIsKeepNewLineMode = false, int iBlockSizeForEachCopy = 8192, std::function<void(uint64_t)> fProgressFunc = nullptr);

        // De-Base64 a file
        static bool FromBase64(std::ifstream &is, std::ostream &os, int iBlockSizeForEachCopy = 8192, std::function<void(uint64_t)> fProgressFunc = nullptr);

        // Sleep ms
        static void Sleep_Ms(uint64_t iMs);
        
        // Sleep s
        static void Sleep_S(uint64_t iSecond);

        // Sleep us
        static void Sleep_Us(uint64_t iUs);
    };
}
#endif // FOUNDATION_H
